package com.example.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.example.entity.ApplyRepair;
import com.example.ext.entity.ExtApplyRepair;
import com.example.service.ApplyRepairService;

import io.swagger.annotations.ApiOperation;

/**
 * Created by douyx on 2018/03/25.
 */
@RestController
@RequestMapping("api/apply")
public class ApplyRepairController {

	@Autowired
	ApplyRepairService applyRepairService;

	/**
	 * 查询列表的信息
	 * 
	 * @param extApplyRepair
	 *                userId:安全管理员编号/维保人员编号
	 *                applyTimeFrom:申请时间起
	 *                applyTimeTo:申请时间止
	 *                approveStatus:审批状态 0 待审批；1 同意； 2 拒绝
	 *                dealStatus:处理状态  0 未处理； 1 已处理
	 *                applyType:申请类型 1 报修； 2 申修
	 *                usedPartyId: 使用单位编号
	 *                maintenancePartyId:维保单位编号
	 *                elevatorId:电梯编号
	 * @return
	 */
	@ApiOperation(value = "查询列表的信息", notes = "查询列表的信息")
	@RequestMapping(value = "/getList", method = RequestMethod.POST)
	Map<String, Object> getList(@RequestBody ExtApplyRepair extApplyRepair) {
		return applyRepairService.queryList(extApplyRepair);
	}

	@ApiOperation(value = "新增信息", notes = "新增信息")
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	Map<String, Object> add(@RequestBody ApplyRepair applyRepair) {
		return applyRepairService.add(applyRepair);
	}

	/**
	 * 更新信息
	 * 
	 * @param applyRepair
	 *                approveStatus:审批状态 0 待审批；1 同意； 2 拒绝
	 *                refuseReason:拒绝原因
	 *                dealStatus:处理状态  0 未处理； 1 已处理
	 *                maintenanceUsedUrl:维保人员签名URL
	 *                usedUserUrl: 安全管理员签名URL
	 *                repairTime:维修时间
	 *                dealTime:处理时间
	 * @return
	 */
	@ApiOperation(value = "更新信息", notes = "更新信息")
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	Map<String, Object> update(@RequestBody ApplyRepair applyRepair) {
		return applyRepairService.update(applyRepair);
	}

	@ApiOperation(value = "查询信息", notes = "查询信息")
	@RequestMapping(value = "/getOne/{id}", method = RequestMethod.POST)
	Map<String, Object> queryById(@PathVariable String id) {
		return applyRepairService.queryById(id);
	}
}
